﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DVDFilmoteka.Sorting
{
    public enum ESorters { ABECEDNI_ORIGINAL, ABECEDNI_CESKY, ZANR, KOMPRESE, ZADNY, DATETIME, HODNOCENI, CSFDRATING, IMDBRATING, DIRECTOR };

    public class SorterStrategy
    {
        private static Dictionary<ESorters, ISorter> sorterPool = null;
        private static ESorters actSorter;
        
        private static void InitializePool()
        {
            sorterPool = new Dictionary<ESorters, ISorter>();

            ISorter sorter = null;

            sorter = new AbecedniCeskySorter();
            sorterPool.Add(ESorters.ABECEDNI_CESKY, sorter);

            sorter = new AbecedniOriginalSorter();
            sorterPool.Add(ESorters.ABECEDNI_ORIGINAL, sorter);

            sorter = new KompreseSorter();
            sorterPool.Add(ESorters.KOMPRESE, sorter);

            sorter = new NoneSorter();
            sorterPool.Add(ESorters.ZADNY, sorter);

            sorter = new ZanrSorter();
            sorterPool.Add(ESorters.ZANR, sorter);

            sorter = new DateSorter();
            sorterPool.Add(ESorters.DATETIME, sorter);

            sorter = new HodnoceniSorter();
            sorterPool.Add(ESorters.HODNOCENI, sorter);

            sorter = new CSFDRatingSorter();
            sorterPool.Add(ESorters.CSFDRATING, sorter);

            sorter = new IMDBRatingSorter();
            sorterPool.Add(ESorters.IMDBRATING, sorter);

            sorter = new DirectorSorter();
            sorterPool.Add(ESorters.DIRECTOR, sorter);
        }

        public static ISorter getSorter()
        {
            if (sorterPool == null)
            {
                setSorter(ESorters.ABECEDNI_CESKY);
            }

            return sorterPool[actSorter];
        }

        public static List<ISorter> GetAvailableSorters()
        {
            if (sorterPool == null) InitializePool();

            return new List<ISorter>(sorterPool.Values);
        }

        public static void setSorter(ESorters newSorter)
        {
            if (sorterPool == null) InitializePool();
            
            actSorter = newSorter;
        }
    }
}
